<template>
	<div>
		<Row :gutter="16" >
            <ICol span="6">
                <router-link v-if="$store.getters.per.wechat_manager_material_create" to="/wechat/manager/material/text/"><Button type="primary">新建文本素材</Button></router-link>
            </ICol>
        </Row>
        <BaseTable ref="table" :url="table.url" :async="false" :header="table.header" ></BaseTable>
	</div>
</template>
<script>
	import {Row,Col,Button,Page} from 'iview';

	import BaseTable  from 'admin/components/table/base';

	export default{
		components:{
			Row,
            'ICol':Col,
            Page,
            Button,
            BaseTable,
        },
		data(){
			return {
				table:{
            		url : '/wechat/manager/material/view/text/list',
            		header: []
            	},
			}
		},
		methods:{
			init(){
				this.$refs.table.init({page:1,length:10});
			}
		},
		created:function(){
        	this.table.header =  [
                {
			        title: '文本名',
			        key: 'name'
			    },
			    {
			        title: '添加时间',
			        key: 'created_at'
			    },
			    {
			        title: '更新时间',
			        key: 'updated_at'
			    },
			    {
			        title: '操作',
			        key: 'action',
			        width: 150,
			        align: 'center',
			        render: (h, params) => {
			            return h('div', [
			            	!this.$store.getters.per.wechat_manager_material_update ? '' :
			                h(Button, {
			                    props: {
			                        type: 'primary',
			                        size: 'small'
			                    },
			                    style: {
			                        marginRight: '5px'
			                    },
			                    on: {
			                        click: () => {
			                        	this.$router.push('/wechat/manager/material/text/'+params.row.id);
			                        }
			                    }
			                }, '编辑'),
			                !this.$store.getters.per.wechat_manager_material_delete ? '' :
			                h(Button, {
			                    props: {
			                        type: 'error',
			                        size: 'small'
			                    },
			                    on: {
			                        click: () => {
			                        	this.$Modal.confirm({
						                    title: '你确定要删除吗？',
						                    content: '一旦删除无法恢复',
						                    onOk: () => {
						                        this.Axios.Wechat.Manager.Material.Text.Del(params.row.id)
									            .then(res =>{
									               	if(!res) return false;
									                this.$refs['table'].tableData();
									            })
						                    }
						                });
			                        }
			                    }
			                }, '删除')
			            ]);
			        }
			    }
            ];
        }
	}
</script>
